/************************************************************
* Copyright (C), 2010-2050, Tencent.
* 模块名    : Precedence DB Operator接口
* 实现功能  :
* 备注      :

* 修改记录  :
* 日 期             修改人              修改内容
  2011-07-26         jasonpeng              创建
***********************************************************/
#ifndef _COOPERATOR_DB_OPERATOR_H_
#define _COOPERATOR_DB_OPERATOR_H_

#include <string>
#include <stdint.h>

#include "app_platform/help_macros.h"
#include "app_platform/intf_service.h"
#include "c2cent/storage/mysqlstorage.h"

#include "b2b2c/cooperator/ddo/cooperatorbaseinfoddo_cooperator.h"
#include "b2b2c/cooperator/ddo/cooperatorlicenseddo_cooperator.h"
#include "b2b2c/cooperator/ddo/cooperatorproddo_cooperator.h"
#include "b2b2c/cooperator/ddo/cooperatorsetddo_cooperator.h"
#include "b2b2c/cooperator/ddo/cooperatormonitormodelddo_cooperator.h"
namespace item
{
    namespace cooperator
    {
        namespace db
        {
            class CCooperatorDBOperator
            {
            public:
                CCooperatorDBOperator(){}
                ~CCooperatorDBOperator(){}

                static int InitDB(IUserDefineCntl* pCntl);

            public:

                /**
                 *
                 *   更新【新增和修改】合作伙伴基本信息
                 *
                 */
                int UpdateCooperatorBaseInfo(
                         const CCntlInfo& rCntlInfo,
                         const std::string& strMachineKey,
                         const std::string& strSource,
                         uint32_t dwSceneId,
                         const b2b2c::cooperator::ddo::CCooperatorBaseInfoDdo& oCooperatorBaseInfoDdo,
                         const std::string& strInReserve,
                         std::string& strErrmsg,
                         std::string& strOutReserve
                        );

                /**
                 *
                 *   设置合作伙伴密码信息
                 *
                 */
                int SetCooperatorPassWd(
                        const CCntlInfo& rCntlInfo,
                        const std::string& strMachineKey,
                        const std::string& strSource,
                        uint32_t dwSceneId,
                        uint64_t ddwCooperatorId,
                        uint8_t cCheckPwFlag,
                        const std::string& strCooperatorOldPassword,
                        const std::string& strCooperatorNewPassword,
                        const std::string& strInReserve,
                        std::string& strErrmsg,
                        std::string& strOutReserve);

                /**
                 *
                 *   获取合作伙伴许可证信息
                 *
                 */
                int GetCooperatorLicense(
                        const CCntlInfo& rCntlInfo,
                        const std::string& strMachineKey,
                        const std::string& strSource,
                        uint32_t dwSceneId,
                        uint64_t ddwCooperatorId,
                        const std::set<uint8_t> & setLicenseType,
                        const std::string& strInReserve,
                        std::string& strErrmsg,
                        std::vector<b2b2c::cooperator::ddo::CCooperatorLicenseDdo> & vecCooperatorLicenseDdo,
                        std::string& strOutReserve
                       );

                /**
                 *
                 *   获取合作伙伴基本信息
                 *
                 */
                int GetCooperatorBaseInfo(
                        const CCntlInfo& rCntlInfo,
                        const std::string& strMachineKey,
                        const std::string& strSource,
                        uint32_t dwSceneId,
                        uint64_t ddwCooperatorId,
                        const std::string& strInReserve,
                        std::string& strErrmsg,
                        b2b2c::cooperator::ddo::CCooperatorBaseInfoDdo& oCooperatorBaseInfoDdo,
                        std::string& strOutReserve
                       );

                /**
                 *
                 *   检查合作伙伴密码信息
                 *
                 */
                int CheckCooperatorPassWd(
                     const CCntlInfo& rCntlInfo,
                     const std::string& strMachineKey,
                     const std::string& strSource,
                     uint32_t dwSceneId,
                     uint64_t ddwCooperatorId,
                     const std::string& strCooperatorPassword,
                     const std::string& strInReserve,
                     std::string& strErrmsg,
                     std::string& strOutReserve
                    );

                /**
                 *
                 *   更新【新增和修改】合作伙伴许可证信息
                 *
                 */
                int UpdateCooperatorLicense(
                     const CCntlInfo& rCntlInfo,
                     const std::string& strMachineKey,
                     const std::string& strSource,
                     uint32_t dwSceneId,
                     const b2b2c::cooperator::ddo::CCooperatorLicenseDdo& oCooperatorLicenseDdo,
                     const std::string& strInReserve,
                     std::string& strErrmsg,
                     std::string& strOutReserve
                    );

                /**
                 *
                 *   更新【新增和修改】合作伙伴子帐号信息
                 *
                 */
                int UpdateCooperatorSubAccount(
                     const CCntlInfo& rCntlInfo,
                     const std::string& strMachineKey,
                     const std::string& strSource,
                     uint32_t dwSceneId,
                     uint32_t dwCooperatorId,
                     const std::vector<b2b2c::cooperator::ddo::CCooperatorSubAccountDdo>& vecCooperatorSubAccountDdo,
                     const std::string& strInReserve,
                     std::string& strErrmsg,
                     std::string& strOutReserve
                    );

                /**
                 *
                 *   获取合作伙伴子帐号信息
                 *
                 */
                int GetCooperatorSubAccount(
                    const CCntlInfo& rCntlInfo,
                    const std::string& strMachineKey,
                    const std::string& strSource,
                    uint32_t dwSceneId,
                    uint64_t ddwCooperatorId,
                    std::vector<b2b2c::cooperator::ddo::CCooperatorSubAccountDdo>  &vecCooperatorSubAccountDdo,
                    const std::string& strInReserve,
                    std::string& strErrmsg,
                    std::string& strOutReserve);

                int GetCooperatorKey(
                                const CCntlInfo& rCntlInfo,
                                const std::string& strMachineKey,
                                const std::string& strSource,
                                uint32_t dwSceneId,
                                uint64_t ddwCooperatorId,
                                const std::string& strInReserve,
                                std::string& strErrmsg,
                                std::string& strSCooperatorKey,
                                std::string& strOutReserve);

               int32_t SetCooperatorPro(
                                const CCntlInfo& rCntlInfo,
                                const std::string& strMachineKey,
                                const std::string& strSource,
                                uint32_t dwSceneId,
                                uint64_t ddwOption,
                                const b2b2c::cooperator::ddo::CCooperatorProDdo& oCooperatorProDdo,
                                const std::string& strInReserve,
                                std::string& strErrmsg,
                                std::string& strOutReserve
                    );

               int32_t SetCooperatorInfo(
                         const CCntlInfo& rCntlInfo,
                         const std::string& strMachineKey,
                         const std::string& strSource,
                         uint32_t dwSceneId,
                         uint64_t ddwOption,
                         const b2b2c::cooperator::ddo::CCooperatorSetDdo& oCooperatorSetDdo,
                         const std::string& strInReserve,
                         std::string& strErrmsg,
                         std::string& strOutReserve
                        );

               	/**
               	 *
               	 *   获取价格告警模版列表
               	 *
               	 */
               	int32_t GetCooperatorMonitorModelList(
               		 const CCntlInfo& rCntlInfo,
               		 const std::string& strMachineKey,
               		 const std::string& strSource,
               		 uint32_t dwSceneId,
               		 uint32_t dwCooperatorId,
               		 const std::string& strInReserve,
               		 std::string& strErrmsg,
               		 std::vector<b2b2c::cooperator::ddo::CCooperatorMonitorModelDdo> & vecCooperatorMonitorModelDdo,
               		 std::string& strOutReserve
               		);

               	/**
				 *
				 *   通过模版ID获取告警模版
				 *
				 */
				int32_t GetCooperatorMonitorModel(
					 const CCntlInfo& rCntlInfo,
					 const std::string& strMachineKey,
					 const std::string& strSource,
					 uint32_t dwSceneId,
					 uint32_t dwCooperatorId,
					 uint32_t dwModelId,
					 const std::string& strInReserve,
					 std::string& strErrmsg,
					 b2b2c::cooperator::ddo::CCooperatorMonitorModelDdo& oCooperatorMonitorModelDdo,
					 std::string& strOutReserve
					);

				/**
				 *
				 *   新增或者更新告警模版
				 *
				 */
				int32_t UpdateCooperatorMonitorModel(
					 const CCntlInfo& rCntlInfo,
					 const std::string& strMachineKey,
					 const std::string& strSource,
					 uint32_t dwSceneId,
					 const b2b2c::cooperator::ddo::CCooperatorMonitorModelDdo& oCooperatorMonitorModelDdo,
					 const std::string& strInReserve,
					 std::string& strErrmsg,
					 std::string& strOutReserve
					);

				/**
				 *
				 *   删除告警模版
				 *
				 */
				int32_t DeleteCooperatorMonitorModel(
					 const CCntlInfo& rCntlInfo,
					 const std::string& strMachineKey,
					 const std::string& strSource,
					 uint32_t dwSceneId,
					 uint32_t dwCooperatorId,
					 uint32_t dwModelId,
					 const std::string& strInReserve,
					 std::string& strErrmsg,
					 std::string& strOutReserve
					);

            private:
                c2cplatform::component::dal::IDBOperator* pIDB;
                c2cent::storage::CMySqlStorage oStorage;

                inline static time_t StrToTime(std::string strTime)
                {
                    if (strTime.empty())
                    {
                        return 0;
                    }

                    struct tm tm_time;
                    strptime(strTime.c_str(), "%Y-%m-%d %H:%M:%S", &tm_time);
                    return mktime(&tm_time);
                }
            };
        }
    }
}

#endif
